package com.pan.download5.config;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public enum ApplicationConfig {
    INSTANCE;
    private Properties property;

    ApplicationConfig() {

        property = new Properties();
        InputStream inputStream = ApplicationConfig.class.getClassLoader()
                .getResourceAsStream("download5/ApplicationConfig.properties");
        try {
            property.load(inputStream);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    private String getValue(String key) {
        String value = property.getProperty(key);
        return value;
    }

    private Integer getIntValue(String key) {
        String value = getValue(key);
        if (value == null) {
            throw new RuntimeException("The Property does not exist: " + key);
        }
        return Integer.parseInt(value);
    }

    private Boolean getBoolValue(String key) {
        String value = getValue(key);
        if (value == null) {
            throw new RuntimeException("The Property does not exist: " + key);
        }
        return Boolean.parseBoolean(value);
    }

    public String getOutputDir() {
        return getValue("story.output.dir");
    }

    public boolean getWriteAppend() {
        return getBoolValue("story.write.append");
    }

    public boolean getClearTitle(){
        return getBoolValue("task.title.clear");
    }
    public int getTaskThreadCount() {
        return getIntValue("task.thread.count");
    }

    public int getTaskErrorWait() {
        return getIntValue("task.error.wait");
    }

    public int getTaskErrorCount() {
        return getIntValue("task.error.count");
    }

    public String getLineConfigPath() {
        return getValue("line.config.path");
    }

    public String getTargetCrawlerUrl(){
        return getValue("target.crawler.url");
    }

    public String getAutoCrawlerPath(){
        return getValue("auto.crawler.path");
    }

    public String getAuto2CrawlerPath(){
        return getValue("auto2.crawler.path");
    }
}
